<template>
  <div>
    <form report-submit @submit='myquestion'>
      <l-input label-width="250" label-layout="right" label="问题标题：" placeholder="请输入问题的标题"  l-class="title" required="true" name="title"></l-input>
      <l-textarea l-class="space" placeholder='请输入问题详情....' maxlength='140' name="content"  l-placeholder-class='question'  >
      </l-textarea>

      <view class='space'></view>

      <view class="m_button-line">
        <block wx:for="i <= 4" wx:key="i">
          <view class='m_button-line-1'></view>
          <view class='m_button-line-2'></view>
          <view class='m_button-line-3'></view>
          <view class='m_button-line-2'></view>
        </block>
      </view>

      <l-input l-class="space" label-layout="right" label="正方观点：" placeholder="请输入正方观点" name="positiveView"></l-input>

      <l-input l-class="space" label-layout="right" label="反方观点：" placeholder="请输入反方观点" name="negativeView"></l-input>


      <button class="button0" form-type='submit'>✓</button>
      <button class="button1"  @click="clickEvent">✗</button>
    </form>

  </div>
</template>

<script>
  export default {
    name: 'AddQuestion',
    data () {
      return {
      }
    },
    methods: {
      clickEvent () {
        console.log('00000')
        wx.switchTab({
          url: '../pages/home'
        })
      },
      myquestion (res) {
        console.log(res.mp.detail.value.content)
        if (res.mp.detail.value.content === '' || res.mp.detail.title === '') {
          console.log('不可以继续走')
          wx.showToast({
            title: '不允许空值哦',
            icon: 'loading',
            duration: 1000
          })
          return false
        } else {
          console.log('可以继续走')
        }

        var res1 = res.mp.detail.value
        wx.request({
          url: 'http://47.94.166.187:8080/miniProgram/addQuestion',
          data: {
            token: wx.getStorageSync('token'),
            content: res.mp.detail.value.content,
            title: res.mp.detail.value.title,
            positiveView: res.mp.detail.value.positiveView,
            negativeView: res.mp.detail.value.negativeView
          },
          success () {
            if (res1.jump === false) {
              wx.showToast({
                title: '前往主页',
                duration: 2000,
                success (res) {
                  setTimeout(function () {
                    this.$router.push({ path: '../pages/home', isTab: true })
                  }, 1800)
                }
              })
            } else {
              wx.showToast({
                title: '前往我的提问页',
                duration: 2500,
                success () {
                  wx.request({
                    url: 'http://47.94.166.187:8080/miniProgram/selAllMyQuestions',
                    data: {
                      token: wx.getStorageSync('token')
                    },
                    success (res) {
                      wx.reLaunch({
                        url: '../pages/home?questionId=' + res.data.object[0].questionId
                      })
                    }
                  })
                }
              })
            }
          }
        }
        )
      }
    }
  }
</script>

<style>
  .m_button-line {
    display: flex;
    width: 100%;
    justify-content: center;
  }

  .m_button-line-1 {
    width: 5%;
    border-bottom: 5rpx solid red;
  }

  .m_button-line-2 {
    width: 3%;
    border-bottom: 5rpx solid white;
  }

  .m_button-line-3 {
    width: 5%;
    border-bottom: 5rpx solid #6495ed;
  }

  .space {
    margin-top: 40rpx;
    margin-left: 25rpx;
  }

  .button0 {
    font-size: 50rpx;
    color: white;
    position: fixed !important;
    bottom: 10rpx !important;
    line-height: 85rpx;
    height: 85rpx;
    width: 350rpx;
    right: 15rpx;
    background-color: lightgreen;
  }

  .button1 {
    font-size: 50rpx;
    color: white;
    line-height: 85rpx;
    height: 85rpx;
    width: 350rpx;
    background-color: red;
    height: 85rpx !important;
    position: fixed !important;
    bottom: 10rpx !important;
    left: 15rpx !important;
  }

  .fabu {
    width: 70rpx;
    height: 70rpx;
  }

</style>
